package src 
{
	import adobe.utils.CustomActions;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	/**
	 * ...
	 * @author Felipe Soares Pinhel
	 */
	public class Hud extends Sprite
	{
		private var life : Life;
		private var lifeMax :int = 3; 
		private var lifeList : Array;
		
		private var pointsIntTxt : TextField;
		private var pointsTxt : TextField;
		private var timerTxt : TextField;
		private var chrono : TextField;
		
		private var pointsIntFormat : TextFormat;
		private var pointsFormat : TextFormat;
		private var timerFormat : TextFormat;
		private var chronoFormat : TextFormat;
		
		private var fonte01 : Fonte01;
		
		private var countFrame : int = 0;
		private var countMin : int = 0;
		private var countHour : int = 0;
		private var countMinZero : String;
		private var countHourZero : String;
		
		
		
		
		public function Hud() 
		{
			
			init();
			
		}
		
		private function init() : void
		{
			trace("HUD");
			
			lifeList = new Array();
			
			for ( var i : int = 0; i < lifeMax; i++ )
			{
				life = new Life();
				life.x = ((20 + (40 * (lifeMax - 1) ) ) - (lifeList.length * 40));
				life.y = 25;
				this.addChild(life);
				
				lifeList.push(life);
			}
			
			fonte01 = new Fonte01();
			
			
			pointsIntFormat = new TextFormat();
			pointsIntFormat.size = 12;
			pointsIntFormat.font = "Calibri";
			pointsIntFormat.align = "center";
			
			pointsIntTxt = new TextField();
			pointsIntTxt.defaultTextFormat = pointsIntFormat;
			pointsIntTxt.x = (this.width * 9/11);
			pointsIntTxt.y = 4;
			pointsIntTxt.width = 95;
			pointsIntTxt.height = 15;
			pointsIntTxt.background = true;
			pointsIntTxt.backgroundColor = 0x003300;
			pointsIntTxt.text = "Points";
			pointsIntTxt.selectable = false;
			this.addChild(pointsIntTxt);
			
			
			pointsFormat = new TextFormat();
			pointsFormat.size = 20;
			pointsFormat.font = "Calibri";
			pointsFormat.align = "center";
			
			pointsTxt = new TextField();
			pointsTxt.defaultTextFormat = pointsFormat;
			pointsTxt.x = (this.width * 9/11);
			pointsIntTxt.y = 4;
			pointsTxt.y = 20;
			pointsTxt.width = 95;
			pointsTxt.height = 25;
			pointsTxt.background = true;
			pointsTxt.backgroundColor = 0x003300;
			pointsTxt.text = "000"
			pointsTxt.selectable = false;
			this.addChild(pointsTxt);
			
			
			timerFormat = new TextFormat();
			timerFormat.size = 12;
			timerFormat.font = "Calibri";
			timerFormat.align = "center";
			
			timerTxt = new TextField();
			timerTxt.defaultTextFormat = timerFormat;
			timerTxt.x = (this.width*  37/52 )
			timerTxt.y = 4;
			timerTxt.width = 50;
			timerTxt.height = 15;
			timerTxt.background = true;
			timerTxt.backgroundColor = 0x00FF00;
			timerTxt.text = "Timer";
			timerTxt.selectable = false;
			this.addChild(timerTxt);
			
			
			chronoFormat = new TextFormat();
			chronoFormat.size = 20;
			chronoFormat.font = "Calibri";
			chronoFormat.align = "center";
			
			chrono = new TextField();
			chrono.defaultTextFormat = chronoFormat;
			chrono.x = (this.width*  37/52 );
			chrono.y = 20;
			chrono.width = 50;
			chrono.height = 25;
			chrono.background = true;
			chrono.backgroundColor = 0x00FF00;
			chrono.text = "" + countHour + ":" + countMin;
			chrono.selectable = false;
			this.addChild(chrono);
			
		}
		
		public function update() : void
		{
			countFrame++;
			chrono.text = ""+ countHourZero + countHour + ":" + countMinZero + countMin;
			
			if (countFrame >= 24)
			{
				countFrame = 0;
				countMin++;
			}
			if (countMin >= 60)
			{
				countMin = 0;
				countHour++;
			}
						
			if (countMin <= 9)
			{
				countMinZero = "0";
			}else {
				countMinZero = "";
			}
			
			if (countHour <= 9)
			{
				countHourZero = "0";
			}else {
				countHourZero = "";
			}
			
		}
		
		
	}

}